package com.tencent.qcloud.qiaoqiao.ui.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tencent.qcloud.qiaoqiao.R;
import com.tencent.qcloud.qiaoqiao.common.utils.TCUtils;
import com.tencent.qcloud.qiaoqiao.ui.bean.CollectBean;
import com.tencent.qcloud.qiaoqiao.ui.tools.utilCode.ScreenUtils;
import com.tencent.qcloud.qiaoqiao.ui.tools.utilCode.TimeUtils;

import de.hdodenhof.circleimageview.CircleImageView;

public class CollectAdapter extends BaseQuickAdapter<CollectBean.ListBean, BaseViewHolder> {

    public CollectAdapter() {
        super(R.layout.adapter_collect);
    }

//    @Override
//    public CollectAdapter onCreateVH(ViewGroup parent, int viewType) {
//        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_ugc_item, null);
//        DisplayMetrics dm = parent.getResources().getDisplayMetrics();
//        int width = dm.widthPixels;
//        itemView.setLayoutParams(new RecyclerView.LayoutParams(width / 2, width / 2));
//        return new CollectAdapter(itemView);
//    }
    @Override
    protected void convert(final BaseViewHolder viewHolder, final CollectBean.ListBean item) {
        TextView video_title = viewHolder.getView(R.id.video_title);
        ImageView video_bg_avatar = viewHolder.getView(R.id.video_bg_avatar);
        CircleImageView video_name_avatar = viewHolder.getView(R.id.video_name_avatar);
        video_title.setText(item.getTitle());
        TextView video_context = viewHolder.getView(R.id.video_context);
        video_context.setText(item.getTitle());
        TextView video_time = viewHolder.getView(R.id.video_time);

        String headUrl = item.getAvatar();
        if (TextUtils.isEmpty(headUrl)) {
            video_name_avatar.setImageResource(R.mipmap.home_head_icon);
        }  else {
            RequestManager req = Glide.with(video_bg_avatar.getContext());
            req.load(headUrl).placeholder(R.drawable.bg_ugc).into(video_name_avatar);
        }

        String headUrl2 = item.getFrontcover();
        if (TextUtils.isEmpty(headUrl2)) {
            video_name_avatar.setImageResource(R.mipmap.home_head_icon);
        }  else {
            RequestManager req = Glide.with(video_bg_avatar.getContext());
            req.load(headUrl).placeholder(R.drawable.bg_ugc).into(video_name_avatar);
        }


        String cover = item.getFrontcover();
        if (TextUtils.isEmpty(cover)) {
            video_bg_avatar.setImageResource(R.drawable.bg_ugc);
        } else {
            RequestManager req = Glide.with(video_bg_avatar.getContext());
            req.load(cover).placeholder(R.drawable.bg_ugc).into(video_bg_avatar);
        }
        //video_bg_avatar.setLayoutParams(new RecyclerView.LayoutParams(width / 2, width / 2));
        String nickname = item.getNickname();
        //主播昵称
        if (TextUtils.isEmpty(item.getNickname()) || "null".equals(nickname)) {
            video_title.setText(TCUtils.getLimitString(item.getUserid(),10));
        } else {
            video_title.setText(TCUtils.getLimitString(nickname, 10));
        }
        //小视频创建时间（发布时间）
        if (!TextUtils.isEmpty(item.getCommend_time())){
            video_time.setText(TimeUtils.generateTimeStr(TimeUtils.convertTimeToLong(item.getCommend_time())));
        } else {
            video_time.setText(TimeUtils.generateTimeStr(TimeUtils.convertTimeToLong(item.getCreate_time())));
        }
        if (!TextUtils.isEmpty(item.getCollection_time())){
            video_time.setText(TimeUtils.generateTimeStr(TimeUtils.convertTimeToLong(item.getCollection_time())));
        }
    }

}